package com.neu.af.controller;

import com.github.pagehelper.PageInfo;
import com.neu.af.dataFilter.entity.AbData;
import com.neu.af.dataFilter.entity.AbDataExample;
import com.neu.af.dataFilter.service.impl.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Date;
import java.sql.Timestamp;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/abDataOp")
public class AbDatacontroller {

    @Autowired
    private BasicAbDataServiceImpl basicAbDataServiceImpl;

    public AbDatacontroller() {
    }

    @RequestMapping("/add")
    public void add(AbData AbData) {
        basicAbDataServiceImpl.insert(AbData);
    }

    @RequestMapping("/delete")
    public void delete(String id) {
        basicAbDataServiceImpl.deleteByPrimaryKey(id);
    }

    @RequestMapping("/update")
    public void update(AbData AbData) {
        basicAbDataServiceImpl.updateByPrimaryKey(AbData);
    }

    @RequestMapping("/select")
    public AbData select(String id) {
        return basicAbDataServiceImpl.selectByPrimaryKey(id);
    }

    @RequestMapping("/list")
    public List<AbData> list() {
        return basicAbDataServiceImpl.selectByExample(new AbDataExample());
    }

    @RequestMapping("/countByExample")
    public Integer countByExample() {
        return basicAbDataServiceImpl.countByExample(new AbDataExample());
    }

    @RequestMapping("/conditionSelect")
    public PageInfo<AbData> conditionSelect(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                            @RequestParam(value = "startTime", required = false) Timestamp startTime,
                                            @RequestParam(value = "endTime", required = false) Timestamp endTime,
                                            @RequestParam(value = "descriptor", required = false) String descriptor,
                                            @RequestParam(value = "type", required = false) Integer type,
                                            @RequestParam(value = "alarmClass", required = false) Integer alarmClass,
                                            @RequestParam(value = "jizuname", required = false) String jizuname) {

        return basicAbDataServiceImpl.ConditionSelect(startTime, endTime, descriptor, type, alarmClass, pageNum, jizuname);
    }

    @RequestMapping("/getjizuName")
    public List<String> getjizuName(){
        return basicAbDataServiceImpl.getjizuName();
    }

    @RequestMapping("/order")
    public PageInfo<AbData> order(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                  @RequestParam(value = "startTime", required = false) Timestamp startTime,
                                  @RequestParam(value = "tagName", required = false) String tagName) {
        return basicAbDataServiceImpl.OrderingAbData(startTime, tagName, pageNum);
    }

    @RequestMapping("/sumClassByWeek")
    public List<Map> sumClassByWeek(@RequestParam(value = "year", defaultValue = "1") int year,
                                    @RequestParam(value = "week", defaultValue = "1") int week) {
        return basicAbDataServiceImpl.sumClassByWeek(year, week);
    }

    @RequestMapping("/sumTagByWeek")
    public List<Map> sumTagByWeek(@RequestParam(value = "year", defaultValue = "1") int year,
                                  @RequestParam(value = "week", defaultValue = "1") int week) {
        return basicAbDataServiceImpl.sumTagByWeek(year, week);
    }

    @RequestMapping("/sumClassByDay")
    public List<Map> sumClassByDay(@RequestParam(value = "year", defaultValue = "1") int year,
                                   @RequestParam(value = "week", defaultValue = "1") int week) {
        return basicAbDataServiceImpl.sumClassByDay(year, week);
    }

    @RequestMapping("/comparisonByClass")
    public List<Map> comparisonByClass(@RequestParam(value = "year", defaultValue = "1") int year,
                                       @RequestParam(value = "week", defaultValue = "1") int week) {
        return basicAbDataServiceImpl.comparisonByClass(year, week);
    }
}

